﻿Public Class QuanLyChiTienNhanh

    Private mapc As String = ""

    Private Sub QuanLyChiTienNhanh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cbNguoiChi.DataSource = ProcFunc.ExecuteFuncSQL("select * from [User]")
        cbNguoiChi.ValueMember = "MaUser"
        cbNguoiChi.DisplayMember = "TenUser"
        cbNguoiChi.SelectedIndex = -1

    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If cbNguoiChi.Text <> "" And txtSoTienChi.Text <> "" Then
            'Tao ma phieu chi
            Dim str = "00"
            Dim day As String = str.Substring(0, 2 - dateNgayChi.Value.Day.ToString.Length) & dateNgayChi.Value.Day
            Dim month As String = str.Substring(0, 2 - dateNgayChi.Value.Month.ToString.Length) & dateNgayChi.Value.Month
            Dim year As String = dateNgayChi.Value.Year.ToString.Substring(dateNgayChi.Value.Year.ToString.Length - 2, 2)
            mapc = ProcFunc.ExecuteFuncSSQL("select max(MaPhieuChi) from PhieuChi where MaPhieuChi like N'PC" & day & month & year & "%'").ToString()
            If mapc = String.Empty Then
                mapc = "PC" + day & month & year & "0001"
            Else
                mapc = "PC" & (mapc.Substring(2, mapc.Length - 2) + 1)
            End If
            '//

            str = "insert into PhieuChi values ('" & mapc & "','" & cbNguoiChi.SelectedValue & "','NH1','CP6','" &
                String.Format("{0:yyyy-MM-dd}", dateNgayChi.Value) & "','" & txtSoTienChi.Value.ToString & "',N'')"
            ProcFunc.ExecuteProcSQL(str)
            MessageBox.Show("Dữ liệu đã được thêm")
        Else
            MessageBox.Show("Xin vui lòng điền đủ thông tin")
        End If
    End Sub
End Class